﻿#include "CSVTool.h"
#include "Logger.h"
#include "RETool.h"
#include "Setting.h"
#include "SimpleSpyderFactory.h"
#include <QCoreApplication>
#include <QNetworkAccessManager>
#include <QString>
#include <QTimer>
// 测试代码
void Exit()
{
    Settings::GetInstance().SyncSettings();
    QCoreApplication::exit();
}
void testLog()
{
    Logger::GetInstance().LogInfo("ganniliang_info");
    Logger::GetInstance().LogWarning("ganniliang_waining");
    Logger::GetInstance().LogError("ganniliang_error");
    Logger::GetInstance().LogCriticalError("ganniliang_critical");
    QVector<QString> header = {"title", "url"};
    CSVTool          csvTool("spyder.csv");
    QVector<QString> data = {"liuxiaochou:www.baidu.com", "liyingcheng:www.gg.com"};

    csvTool.WriteCSV(header, data, "utf-8");
    QVector<QString> vec = csvTool.readCSV();
    for (auto& item : vec) { qDebug() << item << " "; }
}
int main(int argc, char* argv[])
{
    QCoreApplication a(argc, argv);

    std::shared_ptr<Spyder> crawler = SimpleSpiderFactory::CreateSpyder(SPIDERTYPE::LINK);
    QSet<QUrl>              urls    = {QUrl("https://www.baidu.com"),
                       QUrl("https://www.sina.com.cn"),
                       QUrl("https://www.sohu.com")};
    QObject::connect(crawler.get(), &Spyder::CrawlingFinished, Exit);
    crawler->StartCrawling(urls);
    Settings::GetInstance().SetValue("caonima", "ganniliang");
    // 等待一段时间或等待用户输入
    // QTimer::singleShot(10000, &a, &QCoreApplication::quit);   // 10秒后退出
    return a.exec();
}